﻿Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class wsAJAXAutoComplete
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

    Public Function ListaNomesUnidades(ByVal prefixText As String, ByVal count As Integer) As String()
        count = 10
        Dim cn As New SqlClient.SqlConnection("Data Source=desenv;Ini tial Catalog=DBSaude;User ID=sa;Password=smtidesenv")
        cn.Open()
        Dim cmd As New SqlClient.SqlCommand

        Dim dt As New DataTable
        cmd.Connection = cn
        cmd.CommandText = "Select * from SAUDEUnidadesSaude where UnidadeNome LIKE @prefixText  "

        Dim dda As New SqlClient.SqlDataAdapter(cmd)
        dda.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%"

        dda.Fill(dt)
        Dim nomes(dt.Rows.Count) As String
        Dim i As Integer = 0
        For Each dr As DataRow In dt.Rows
            nomes.SetValue(dr("UnidadeNome").ToString, i)
            i += 1
        Next
        cn.Close()
        Return nomes
    End Function


    Public Function ListaNomes(ByVal prefixText As String, ByVal count As Integer) As String()
        Dim strResult As New ArrayList
        Dim str(5) As String
        str(0) = "aabbbee"
        str(1) = "abbpff"
        str(2) = "cocicpco"
        str(3) = "popopo"
        str(4) = "poappape"


        For Each item As String In str
            If item.ToLower.ToString.StartsWith(prefixText) Then
                strResult.Add(item)
            End If

        Next
        Return strResult.ToArray(str.GetType)
    End Function
End Class